package com.yc.common.res;

import com.yc.common.enums.ResultCode;

import java.io.Serializable;

/**
 * @Classname BaseUtil
 * @Description 统一返回类
 * @Version 1.0.0
 * @Date 2022/7/11 11:04
 * @Created by Mikechen
 */
public class ResultClass<T>  implements Serializable{
    private Integer code;
    private String msg;
    private long timestamp;
    private T data;

    public ResultClass(){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResultClass<T> success(T data){
        ResultClass result = new ResultClass();
        result.code= ResultCode.SUCCESS.getCode();
        result.msg=ResultCode.SUCCESS.getMsg();
        result.data=data;
        return result;
    }
    public static <T> ResultClass<T> success(String msg,T data){
        ResultClass result = new ResultClass();
        result.code= ResultCode.SUCCESS.getCode();
        result.msg=msg;
        result.data=data;
        return result;
    }


    public static <T> ResultClass<T> success(){
        ResultClass result = new ResultClass();
        result.code=ResultCode.SUCCESS.getCode();
        result.msg=ResultCode.SUCCESS.getMsg();
        return result;
    }

    public static <T> ResultClass<T> fail(String msg){
        ResultClass result = new ResultClass();
        result.code=ResultCode.SUCCESS.getCode();
        result.msg=msg;
        return result;
    }

    public static <T> ResultClass<T> fail(Integer code,String msg){
        ResultClass result = new ResultClass();
        result.code=code;
        result.msg=msg;
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
